package com.see51.demo.see51demo;


import android.app.Application;
import android.util.Log;

import com.see51.demo.see51demo.Model.DevFileInfo;
import com.see51.sdk.java.I51SeeListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * Created by dell on 2019/4/4.
 */


public class See51App extends Application  implements I51SeeListener
{
    public String m_strAccessToke;

    public  List<DevInfo>   m_DevList = new ArrayList<DevInfo>();//实体类

    private Map<String, DevFileInfo> m_DownFileMap = new HashMap<String,DevFileInfo>();
    @Override
    public void onCreate()
    {
        super.onCreate();
    }
    int m_nObjId=0;
    public void  SetObjectId(int Id)
    {
        m_nObjId=Id;
    }
    public int   GetObjectId()
    {
       return m_nObjId;
    }
    public  void  On51SeeAv(int devHandle,     int frame_type,
                            int	av_type,
                            int	size,
                            int	frameRate_samplingRate,
                            int	timestamp,
                            int	video_cap,
                            int	reserved, byte[] data)
    {
        Log.d("句柄",""+devHandle+"--avtype:"+av_type+"--size:"+size);
    }
    //设备断开通知
    public void    OnClose(int devHandel )
    {

    }
    //文件下载完成通知
    public void    OnDownFileOver(int devHandel,String fileName)
    {

        int pt=fileName.lastIndexOf("/");
        String DevId = fileName.substring(0,pt);
        int pt2=DevId.lastIndexOf("/")+1;
        DevId=DevId.substring(pt2);

        pt++;
        String name = fileName.substring(pt);
        Log.d("xx：",DevId+":"+ name);

        String key = GetStrKey(DevId,name);
        SetDownInfo(key,3);
    }
    public  boolean HasDownInfo(String key)
    {
        synchronized(m_DownFileMap)
        {
            if (m_DownFileMap.containsKey(key))
                return true;
            return false;
        }
    }

    public void  GetDownFileMap( List<DevFileInfo>  list)
    {
        synchronized(m_DownFileMap)
        {
            Iterator iter = m_DownFileMap.entrySet().iterator();
            while (iter.hasNext())
            {
                Map.Entry entry = (Map.Entry) iter.next();
                DevFileInfo val = (DevFileInfo)entry.getValue();
                list.add(val);
             }

        }
    }
    public int AddDownInfo(String key,DevFileInfo info)
    {
        synchronized(m_DownFileMap)
        {

            if (m_DownFileMap.containsKey(key))
            {
                return 0;
            }else {
                m_DownFileMap.put(key, info);
                return 1;
            }
        }
    }

    public int SetDownInfo(String key,int Downstate)
    {
        synchronized(m_DownFileMap)
        {

            if (m_DownFileMap.containsKey(key))
            {
                ((DevFileInfo)m_DownFileMap.get(key)).DownState = Downstate;
                return 1;
            }else {
                return 0;
            }
        }
    }
    public String GetStrKey(String DevId,String filename)
    {
        String key=DevId+"_"+filename;
        return key;
    }
}
